# coding=utf-8
# from Tkinter import *
# root = Tk()
# # 创建一个Canvas，设置其背景色为白色
# cv = Canvas(root,bg = 'white')
# # 创建三个rectangle
# rt1 = cv.create_rectangle(
#     10,10,110,110,
#     width = 8,
#     tags = ('r1','r2','r3'))
# def printRect(event):
#     print 'rectangle'
# def printLine(event):
#     print 'line'
# # 绑定item与左键事件
# cv.tag_bind('r1','<Button-1>',printRect)
# # 绑定item与右键事件
# cv.tag_bind('r2','<Button-3>',printLine)
# cv.pack()
# root.mainloop()

from Tkinter import *
# root = Tk()
'''
root.geometry('300x300')
cv = Canvas(root, bg='white', width=1000, height=1000)
d = {1: 'error', 2: 'info', 3: 'question', 4: 'hourglass'}
for i in d:
    cv.create_bitmap((20 * i, 20), bitmap=d[i])
img = PhotoImage(file='D:/temp/50.gif')
# 创建gif图
cv.create_image((150, 150), image=img)
cv.create_line(0,800,800,800,fill="red",arrow="last")
cv.create_line(0,0,0,800,fill="blue",arrow="first")
cv.pack()
root.mainloop()
'''
'''
if __name__ == '__main__':
    root = Canvas(width=1000,height=1000,bg='yellow')
    root.pack(expand=YES, fill=BOTH)
    k=1
    j=1
    for i in range(0,100):
        root.create_oval(500 - k, 500 - k, 500 + k, 500 + k,width=1)
        j = j+k
        k = k+5
    root.pack()
    root.mainloop()
'''

import numpy
import matplotlib
import matplotlib.pyplot as plt
'''
numpy.random.seed(1000)
y = numpy.random.standard_normal(10)
print "y=%s" % y
x = range(len(y))
print "x=%s " % x
plt.plot(y)
plt.show()
'''

''''
numpy.random.seed(1000)
y = numpy.random.standard_normal(10)
plt.plot(y.cumsum())
plt.grid(True)  #增加格点
plt.axis("tight")  # 坐标轴适应数据量 axis 设置坐标轴
print "y=%s" % y
x = range(len(y))
print "x=%s " % x
plt.show()
'''
# 3.plt.xlim 和 plt.ylim 设置每个坐标轴的最小值和最大值
'''
numpy.random.seed(10000)
y = numpy.random.standard_normal(100)
plt.plot(y.cumsum())
plt.grid(True) ##增加格点
plt.xlim(-1,30)
plt.ylim(numpy.min(y.cumsum()-1),numpy.max(y.cumsum()+1))
plt.show()
'''
# 4. 添加标题和标签 plt.title, plt.xlabe, plt.ylabel 离散点, 线
'''
numpy.random.seed(1000)
y =numpy.random.standard_normal(10)
plt.figure(figsize=(7,4)) #画布大小
plt.plot(y.cumsum(),"b",lw=1.5)
plt.plot(y.cumsum(),"ro") #离散的点
plt.grid(True)
plt.axis("tight")  # 坐标轴适应数据量 axis 设置坐标轴
plt.xlabel("x value")
plt.ylabel("y value")
plt.title("x,y simplt Plot")
plt.show()
'''
# 二维数据集
'''
numpy.random.seed(100)
y = numpy.random.standard_normal((10,2))
print y
plt.figure(figsize=(7,4))
plt.plot(y,lw=1.5)
plt.plot(y,'ro')
plt.axis('tight')
plt.grid(True)
plt.title('A Sample Line')
plt.xlim(-1,10)
plt.ylim(numpy.min(y -1),numpy.max(y + 1))
plt.xlabel("x value")
plt.ylabel("y value")
plt.show()
'''
# 添加图例 plt.legend(loc = 0)
'''
numpy.random.seed(100)
y = numpy.random.standard_normal((20,3))
print y
plt.figure(figsize=(7,5))
plt.plot(y[:,0],lw=1.5,label='1st')
plt.plot(y[:,1],lw=1.5 ,label="2st")
plt.plot(y[:,2],lw=1.5 ,label='3st')
plt.plot(y,'ro')
plt.grid(True)
plt.axis('tight')
plt.legend(loc=0)
plt.xlim(-1,20)
plt.ylim(y.min()-1,y.max()+1)
plt.title('Three Sample Line')
plt.xlabel('x value')
plt.ylabel('y value')
plt.show()
'''
'''
import  numpy as np
import matplotlib
# fig,ax1 =plt.subplots() ,ax2 = plt.subplots()  拆分多个小图
# 多个图在一起 ax2 = ax1.twinx()
np.random.seed(1000)
y = np.random.standard_normal((30,2))
plt.figure(figsize=(5,3))
fig,ax1 = plt.subplots()
plt.plot(y[:,0],lw=1.5,label='1st')
plt.plot(y[:,0],'ro')
plt.legend(loc=0)
plt.axis('tight')
plt.grid(True)
plt.xlabel('x0 vaule')
plt.ylabel('y0 vaule')
plt.xlim(-1,30)
plt.ylim(y[:,0].min()-1,y[:,0].max()+1)
plt.title('frist sample line')
fig,ax2 = plt.subplots()
''''''
# ax2 = ax1.twinx()
plt.plot(y[:,1],lw=1.5,label='2nd')
plt.legend(loc=0)
plt.plot(y[:,1],'ro')
plt.grid(True)
plt.axis('tight')
plt.title('Second sample line')
plt.xlabel('x1 vaule')
plt.ylabel('y1 vaule')
plt.xlim(-1,30)
plt.ylim(y[:,1].min()-1,y[:,1].max()+1)
plt.show()
'''
# 直方图  subplot 两行一列,第一个图
'''
import numpy
import matplotlib.pyplot as plt
numpy.random.seed(2000)
y = numpy.random.standard_normal((10,2))
plt.figure(figsize=(10,5))
plt.subplot(121) #两行一列,第一个图
plt.plot(y[:,0],lw=1.5,label='1st')
plt.plot(y[:0,],'ro')
plt.legend(loc = 0)
plt.grid(True)
plt.axis("tight")
plt.xlabel('Frist Index')
plt.ylabel(" y vaule")
plt.title("Frist Sample Line")
plt.subplot(122) #两行一列,第一个图
plt.bar(numpy.arange(len(y)),y[:,1],width=0.5,color='g',label='2nc')
plt.grid(True)
plt.legend(loc=0)
plt.axis("tight")
plt.xlabel('Second Index')
plt.ylabel(" y vaule")
plt.title("Second Sample Line")
plt.show()

'''
# 直方图
'''
import numpy
import matplotlib.pyplot as plt
numpy.random.seed(2000)
y = numpy.random.standard_normal((1000,2))
plt.figure(figsize=(7,5))
plt.hist(y,label=['1st','2nd'],bins=25)
plt.plot(y[:0,],'ro')
plt.legend(loc = 0)
plt.grid(True)
plt.axis("tight")
plt.xlabel('Frist Index')
plt.ylabel(" y vaule")
plt.title("Frist Sample Line")
plt.show()
'''
'''
import numpy
import matplotlib.pyplot as plt
numpy.random.seed(2000)
y = numpy.random.standard_normal((1000,2))
plt.figure(figsize=(7,5))
# plt.hist(y,label=['1st','2nd'],color=['c','m'],bins=20,)
plt.hist(y,label=['1st','2nd'],color=['green','orange'],stacked=True,bins=20,)  #stacked=True 直方图堆叠
plt.plot(y[:0,],'ro')
plt.legend(loc = 0)
plt.grid(True)
plt.axis("tight")
plt.xlabel('Frist Index')
plt.ylabel(" y vaule")
plt.title("Frist Sample Line")
plt.show()
'''
